package train48days;

import java.util.Scanner;
public class Fibonacci数列 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b=0,c=1;
        while (c<=a){
            int temp =b+c;
             b=c;
             c=temp;
        }
        System.out.println(Math.min(c-a,a-b));
    }
}
